﻿@* Generator: Template
    GeneratePrettyNames : true *@
@functions{
    public NFinal.Compile.SqlTemplate.Model.Insert Model { get; set; }
}
#region	var @{@Model.varName}; 插入并返回ID
			if(Model.isDeclaration){
				var @{@Model.varName}=0;
			}
			var __@{@Model.functionName}_@{@Model.varName}_NonQuery = 0;
			var __@{@Model.functionName}_@{@Model.varName}_command__ = new Oracle.ManagedDataAccess.Client.OracleCommand("@{@Model.sql}", @{@Model.connectionVarName});
			@if(Model.isTransaction){
			@:__@{@Model.functionName}_@{@Model.varName}_command__.Transaction=@{@Model.transactionVarName};
			}
			@if(Model.sqlVarParameters.Count>0){
			@:var __@{@Model.functionName}_@{@Model.varName}_parameters__=new Oracle.ManagedDataAccess.Client.OracleParameter[@{@Model.sqlVarParameters.Count}];
			}
			@{int i=0;}
			@foreach(var sqlVarParameter in Model.sqlVarParameters){
			if(sqlVarParameter.field.length>0){
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new Oracle.ManagedDataAccess.Client.OracleParameter(":@{@sqlVarParameter.name}",Oracle.ManagedDataAccess.Client.OracleDbType.@{@sqlVarParameter.field.dbType},@{@sqlVarParameter.field.length});
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i].Value = @{@sqlVarParameter.csharpName}.WithDBNull();
			}else{
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i] = new Oracle.ManagedDataAccess.Client.OracleParameter(":@{@sqlVarParameter.name}",Oracle.ManagedDataAccess.Client.OracleDbType.@{@sqlVarParameter.field.dbType});
			@:__@{@Model.functionName}_@{@Model.varName}_parameters__[@i].Value = @{@sqlVarParameter.csharpName}.WithDBNull();
			}
			i++;
			}
			@if(Model.sqlVarParameters.Count>0){
			@:__@{@Model.functionName}_@{@Model.varName}_command__.Parameters.AddRange(__@{@Model.functionName}_@{@Model.varName}_parameters__);
			}
			try
			{
				__@{@Model.functionName}_@{@Model.varName}_NonQuery = __@{@Model.functionName}_@{@Model.varName}_command__.ExecuteNonQuery();
				__@{@Model.functionName}_@{@Model.varName}_command__.Dispose();
				if(__@{@Model.functionName}_@{@Model.varName}_NonQuery>0)
				{
					__@{@Model.functionName}_@{@Model.varName}_command__ = new Oracle.ManagedDataAccess.Client.OracleCommand("select @{@Model.tableName}_id_sequence.currval  from dual", @{@Model.connectionVarName});
					@if(Model.isTransaction){
					@:__@{@Model.functionName}_@{@Model.varName}_command__.Transaction=@{@Model.transactionVarName};
					}
					@{@Model.varName} = __@{@Model.functionName}_@{@Model.varName}_command__.ExecuteScalar().AsVar();
					__@{@Model.functionName}_@{@Model.varName}_command__.Dispose();
				}
			}
			catch
			{
				__@{@Model.functionName}_@{@Model.varName}_command__.Dispose();
			}
			#endregion
			